<template>
  <!-- 场站发送通知给车队 2018/3/7 11:44 zhangQ -->
  <div>
    <Row :style="{minHeight:350+'px'}">
      <i-col span="20">
        <Form ref="sendNoticeForm" :model="sendNoticeForm" label-position="left" :label-width="100">
          <!--<template v-for="(item, index) in trackName">
            <FormItem :label="item.login_name">
              <Select v-model="sendNoticeForm.data[index].address" filterable multiple :value="sendNoticeForm.data[index].address" style="width: 400px">
                <template v-for="(addressItem, index) in address">
                  <Option :value="addressItem" :key="index">{{addressItem}}</Option>
                </template>
              </Select>
            </FormItem>
          </template>-->
          <FormItem label="选择车队">
            <CheckboxGroup v-model="checkTrackName">
              <template v-for="(item, index) in trackName">
                <FormItem>
                  <Checkbox :label="item.login_name">
                    <span>{{ item.login_name}}</span>
                  </Checkbox>
                </FormItem>
              </template>
            </CheckboxGroup>
          </FormItem>
        </Form>
      </i-col>
    </Row>
    <div class="xlinkModal-footer">
      <Button type="primary" @click="sendNoticeToFleet">确认发送</Button>
    </div>
  </div>
</template>

<script>
  import { getTrackList, getOwnFleet, getAddressList, sendNotice } from '@api/backEnd/station'
  // import moment from 'moment'

  export default {
    name: 'send-notice',
    data () {
      let sendNoticeForm = {
        paraPositionTrack: '',
        estimateArriveTime: '',
        mainOrderNo: '',
        data: []
      }
      let trackOptions = []
      let trackName = []
      let address = []
      let checkTrackName = []
      let datas = { sendNoticeForm, trackOptions, trackName, address, checkTrackName }
      return datas
    },
    props: {
      currentMainOrder: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    computed: {},
    methods: {
      getData () {
        getTrackList().then(res => {
          if (res.data.isSuccess === 1) {
            this.trackOptions = res.data.data
          }
        })
        getOwnFleet().then(res => {
          if (res.data.isSuccess === 1) {
            this.trackName = res.data.data
            this.newObj = this.trackName
            for (let i = 0; i < this.newObj.length; i++) {
              this.sendNoticeForm.data.push({
                truckName: this.newObj[i].login_name,
                address: []
              })
            }
          }
        })
        getAddressList().then(res => {
          if (res.data.isSuccess === 1) {
            this.address = res.data.data
          }
        })
      },
      /**
       * TODO(发送通知给车队)
       * @auther zhangQ
       * @date 2018/3/16 17:26
       */
      sendNoticeToFleet () {
        // let sendData = {truckName: this.checkTrackName}
        // let val = this.sendNoticeForm.data
        let sendData = []
        this.checkTrackName.forEach((item) => {
          sendData.push({
            truckName: item
          })
        })
        // this.sendNoticeForm.estimateArriveTime = moment(this.sendNoticeForm.estimateArriveTime).format('YYYY-MM-DD HH:mm:ss')
        // const estimateArriveTime = this.sendNoticeForm.estimateArriveTime
        const mainOrderNo = this.currentMainOrder.orderNo
        const data = JSON.stringify(sendData)
        const param = { mainOrderNo, data }
        sendNotice(param).then(res => {
          if (res.data.isSuccess === 1) {
            this.$Message.info('发送成功')
            this.$emit('close', 'sendNotice')
          } else {
            this.$Message.error(res.data.res)
            console.log(res.data.res)
          }
        }).catch((res) => {
          this.$Notice.error({
            title: '获取股道失败',
            desc: res
          })
        })
      }
    },
    mounted () {
      this.getData()
    },
    components: {}
  }
</script>

<style scoped>

</style>
